/*
 * @(#)XfplotColorModel.java        2003/01/01
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//		COLORES DE LA REPRESENTACION SOLIDA		//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

package xfuzzy.xfplot.model;

import java.awt.*;

/**
 * Clase que desarrolla los distintos modelos de colores de la representaci�n
 * en 3D
 * 
 * @author Francisco Jos� Moreno Velo
 *
 */
public class XfplotColorModel {
	
	//----------------------------------------------------------------------------//
	//                            CONSTANTES PUBLICAS                             //
	//----------------------------------------------------------------------------//
	
	public static final int WHITE = 0;
	public static final int HUE_1 = 1;
	public static final int HUE_2 = 2;
	public static final int HUE_3 = 3;
	public static final int HUE_4 = 4;
	public static final int BRI_1 = 5;
	public static final int BRI_2 = 6;
	public static final int BRI_3 = 7;
	public static final int BRI_4 = 8;
	public static final int BRI_5 = 9;
	public static final int B_W = 10;
	public static final int COUNTER = 11;
	
	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                              //
	//----------------------------------------------------------------------------//
	
	/**
	 * C�digo del modelo
	 */
	private int model;
	
	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//
	
	/**
	 * Constructor
	 */
	public XfplotColorModel(int model) {
		this.model = model;
	}
	
 	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//
	
	/**
	 * Obtiene el c�digo del modelo
	 */
	public int getModel() {
		return this.model;
	}
	
	/**
	 * Selecciona el c�digo del modelo
	 */
	public void setModel(int model) {
		this.model = model;
	}
	
	/**
	 * Modifica el modelo seleccionado
	 */
	public void change() {
		this.model = (this.model+1)%COUNTER;
	}
	
	/**
	 * Devuelve el color asociado al valor selecionado
	 */
	public Color getColor(double value) {
		switch(model) {
		case WHITE:
			return Color.white;
		case HUE_1:
			return new Color(Color.HSBtoRGB((float) value, 1.0f, 1.0f));
		case HUE_2:
			return new Color(Color.HSBtoRGB((float) (value/2), 1.0f, 1.0f));
		case HUE_3:
			return new Color(Color.HSBtoRGB((float) (0.25+value/2),1.0f,1.0f));
		case HUE_4:
			return new Color(Color.HSBtoRGB((float) (0.5+value/2), 1.0f, 1.0f));
		case BRI_1:
			return new Color(Color.HSBtoRGB(0.3125f, 1.0f, (float) (0.25+value/2) ));
		case BRI_2:
			return new Color(Color.HSBtoRGB(0.0f, 1.0f, (float) (0.25+value/2) ));
		case BRI_3:
			return new Color(Color.HSBtoRGB(0.859f, 1.0f, (float) (0.25+value/2) ));
		case BRI_4:
			return new Color(Color.HSBtoRGB(0.625f, 1.0f, (float) (0.25+value/2) ));
		case BRI_5:
			return new Color(Color.HSBtoRGB(0.469f, 1.0f, (float) (0.25+value/2) ));
		case B_W:
			return new Color(Color.HSBtoRGB(0.0f, 0.0f, (float) (0.25+value/2) ));
		default: return Color.black;
		}
	}
	
	/**
	 * Devuelve el color asociado al grid
	 */
	public Color getGridColor() {
		switch(model) {
		case WHITE: return Color.red;
		case HUE_1: return Color.red;
		case HUE_2: return Color.red;
		case HUE_3: return Color.red;
		case HUE_4: return Color.red;
		case BRI_1: return Color.red;
		case BRI_2: return Color.red;
		case BRI_3: return Color.red;
		case BRI_4: return Color.red;
		case BRI_5: return Color.red;
		case B_W: return null;
		default: return null;
		}
	}
}
